package com.itheima.bos.service.transit.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheima.bos.dao.transit.InOutStorageInfoRepository;
import com.itheima.bos.dao.transit.TransitInfoRepository;
import com.itheima.bos.domain.transit.InOutStorageInfo;
import com.itheima.bos.domain.transit.TransitInfo;
import com.itheima.bos.service.transit.InOutStorageInfoService;

@Service
@Transactional
public class InOutStorageInfoServiceImpl implements InOutStorageInfoService {
	
	@Autowired
	private InOutStorageInfoRepository inOutStorageInfoRepository;
	
	@Autowired
	private TransitInfoRepository transitInfoRepository;

	@Override
	public void save(String transitInfoId, InOutStorageInfo inOutStorageInfo) {
		//保存出入库信息
		inOutStorageInfoRepository.save(inOutStorageInfo);
		//查询对应的TransitInfo
		TransitInfo transitInfo = transitInfoRepository.findOne(Integer.parseInt(transitInfoId));	
		//关联出入库信息到运输配送对象中
		transitInfo.getInOutStorageInfos().add(inOutStorageInfo);
		//修改状态
		if (inOutStorageInfo.getOperation().equals("到达网点")) {
		
			transitInfo.setStatus("到达网点");
			transitInfo.setOutletAddress(inOutStorageInfo.getAddress());
		}
		
	}

}
